import { createRouter, createWebHistory } from "vue-router";
import First from "@/views/first/index.vue";
import Second from "@/views/second/index.vue";
import Third from "@/views/third/index.vue";
import Fourth from "@/views/fourth/index.vue";
import Zero from "@/views/zero/index.vue";
import store from "@/store";
import Layout from "@/layout/index.vue";

//创建路由

//配置信息中需要页面的相关配置
const menuRoutes = [
  // {
  //   path: "/",
  //   component: ()=>import("@/layout/index.vue"),
  //   redirect: "/First"
  // },
  //第一页
  {
    path: "/First",
    name: "First",
    component: First,
  },
  //第二页
  {
    path: "/Second",
    name: "Second",
    component: Second,
  },
  //第三页
  {
    path: "/Third",
    name: "Third",
    component: Third,
  },
  //第四页
  {
    path: "/Fourth",
    name: "Fourth",
    component: Fourth,
  },
  //封面页
  // {
  //   path: "/Zero",
  //   component: Zero,
  // },
];

const routes = [
  { path: "/", redirect: "/home" },
  {
    path: "/home",
    component: Layout,
    redirect: "/First",
    children: [...menuRoutes],
  },
  //封面页
  {
    path:"/Zero",
    component:Zero,

  }
]

const router = createRouter({
  history: createWebHistory("/"),
  routes,
  strict: true,
})


router.beforeEach((to, from) => {
  if (!store.state.isFengMian && to.path !== "/Zero") {
    return {
      path: "/Zero",
      query: { redirect: to.fullPath },
    }
  } 
});

export default router;
